package com.qin.malldiscount.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qin.malldiscount.domain.SmsCouponHistory;
import com.qin.malldiscount.service.SmsCouponHistoryService;
import com.qin.malldiscount.mapper.SmsCouponHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 覃剑
* @description 针对表【sms_coupon_history(优惠券使用、领取历史表)】的数据库操作Service实现
* @createDate 2022-11-23 16:35:44
*/
@Service
public class SmsCouponHistoryServiceImpl extends ServiceImpl<SmsCouponHistoryMapper, SmsCouponHistory>
    implements SmsCouponHistoryService{
    
    @Autowired
    private SmsCouponHistoryMapper couponHistoryMapper;

    /**
     * 分页查询优惠券领取记录
     * @param couponId 优惠券id
     * @param useStatus 使用状态
     * @param orderSn 使用订单号码
     */
    @Override
    public Page<SmsCouponHistory> list(Long couponId, Integer useStatus, String orderSn, Integer pageSize, Integer pageNum) {
        Page<SmsCouponHistory> historyPage = new Page<>(pageNum, pageSize);
        QueryWrapper<SmsCouponHistory> wrapper = new QueryWrapper<>();
        if (couponId!=null){
            wrapper.eq("coupon_id",couponId);
        }
        if (useStatus!=null){
            wrapper.eq("use_status",useStatus);
        }
        if (orderSn!=null){
            wrapper.eq("order_sn",orderSn);
        }
        Page<SmsCouponHistory> page = couponHistoryMapper.selectPage(historyPage, wrapper);

        return page;
    }
}




